import requests

cookies = {
    'YJSESSIONID': '60A65A0A17FE4BF6957BAB75290733B5',
    'wyhijack': '/uploads/sa-admin/static/kj/vue.min.js_1729132081498',
}

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0',
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
    # 'Accept-Encoding': 'gzip, deflate',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'X-Requested-With': 'XMLHttpRequest',
    'Origin': 'http://59.215.208.54:91',
    'Connection': 'keep-alive',
    'Referer': 'http://59.215.208.54:91/hview/manage/dt/Dictuse.do?ismanage=1',
    # 'Cookie': 'YJSESSIONID=60A65A0A17FE4BF6957BAB75290733B5; wyhijack=/uploads/sa-admin/static/kj/vue.min.js_1729132081498',
    'Priority': 'u=0',
}

data = {
    'noData': 'true',
    'page': '1',
    'rows': '1000',
    'pageindex': '1',
    'ispage': '1',
    'pagesize': '1000',
}

response = requests.post(
    'http://59.215.208.54:91/sysaction.do?ClassName=com.hyysoft.smart.action.sys.DictuserAction.userinfolist_gl&DB_Conn=DbDefault&QueryField=hall_id,Orgcode&hall_id=520300&Orgcode=',
    cookies=cookies,
    headers=headers,
    data=data,
).json()


import pandas as pd

# 假设response['data']是一个包含用户信息的列表，每个元素也是一个列表，包含'Userid', 'Xname', 'WorkNum', 'UserName'等信息
data = response['data']
print(data)
# 直接将列表转换为DataFrame    会自动匹配列表中的json
df = pd.DataFrame(data, columns=['Userid', 'Xname', 'WorkNum', 'UserName'])

# 将DataFrame写入Excel文件
with pd.ExcelWriter('用户信息.xlsx') as writer:
    df.to_excel(writer, index=False)

